package com.buba.controller;


import com.buba.service.MaintenanceLevelService;
import com.buba.service.MaintenanceProgramService;
import common.R;
import entity.maintenance.MaintenanceLevel;
import entity.maintenance.MaintenanceProgram;
import entity.maintenance.dto.MaintenanceProgramDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import utils.pageutil.PageResult;

import java.util.List;

/**
 * <p>
 * 保养项目 前端控制器
 * </p>
 *
 * @author beisheng
 * @since 2023-05-18
 */
@RestController
@RequestMapping("/maintenance-program")
public class MaintenanceProgramController {

    @Autowired
    private MaintenanceProgramService maintenanceProgramService;
    @Autowired
    private MaintenanceLevelService maintenanceLevelService;

    @PostMapping("updateMaintenanceProgram")
    public R updateMaintenanceProgram(@RequestBody MaintenanceProgram maintenanceProgram) {
        boolean b = maintenanceProgramService.updateMaintenanceProgram(maintenanceProgram);
        return b ? R.success() : R.error();

    }

    /**
     * 添加保养项目
     *
     * @param maintenanceProgram
     * @return
     */
    @PostMapping("insMaintenanceProgram")
    public R insMaintenanceProgram(@RequestBody MaintenanceProgram maintenanceProgram) {
        boolean b = maintenanceProgramService.insMaintenanceProgram(maintenanceProgram);
        return b ? R.success() : R.error();

    }

    /**
     * 批量删除
     *
     * @param ids
     * @return
     */
    @PostMapping("delMaintenanceProgram")
    public R delMaintenanceProgram(@RequestBody List<Integer> ids) {
        boolean b = maintenanceProgramService.delMaintenanceProgram(ids);
        return b ? R.success() : R.error();
    }

    /**
     * 分页模糊全查保养项目列表
     *
     * @param maintenanceProgramDto
     * @return
     */
    @PostMapping("selMaintenanceProgram")
    public R selMaintenanceProgram(@RequestBody MaintenanceProgramDto maintenanceProgramDto) {
        PageResult pageResult = maintenanceProgramService.selMaintenanceProgram(maintenanceProgramDto);
        return R.success(pageResult);
    }

    /**
     * 查询保养级别信息
     *
     * @return
     */
    @GetMapping("selMaintenanceLevel")
    public R selMaintenanceLevel() {
        List<MaintenanceLevel> list = maintenanceLevelService.queryAll();
        if (list == null) {
            return R.error("500", "参数错误");
        } else {
            return R.success(list);
        }

    }

}

